import { Request } from '@/utils/request';

/**
 * 上传图片
 * @param formData
 * formData包含 albumID：相册ID，pictures：上传的图片
 * @returns
 */
export function uploadPicture(formData: FormData) {
  return Request.axiosInstance({
    url: '/picture/upload',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  });
}

/**
 * 移动照片到另一个相册
 * @param albumId 移动到的相册ID
 * @param picIds 照片ID数组
 * @returns
 */
export function movePicture(albumId: number, picIds: Array<number>) {
  return Request.axiosInstance({
    url: '/picture/move',
    method: 'put',
    data: { albumId, picIds: JSON.stringify(picIds) }
  });
}

/**
 * 删除照片至回收站
 * @returns
 */
export function delPicture(picIds: Array<number>) {
  return Request.axiosInstance({
    url: '/picture/del',
    method: 'delete',
    params: { picIds: JSON.stringify(picIds) }
  });
}

/**
 * 获取照片列表
 * @param page
 * @param size
 * @returns
 */
export function getPictureList(page: number, size: number) {
  return Request.axiosInstance({
    url: '/picture/list',
    method: 'get',
    params: { page, size }
  });
}

/**
 * 获取某一相册的照片列表
 * @param albumId 相册ID
 * @param page
 * @param size
 */
export function getPictureAlbumList(albumId: number | any, page: number, size: number) {
  return Request.axiosInstance({
    url: '/picture/album_list',
    method: 'get',
    params: { albumId, page, size }
  });
}

/**
 * 根据文本查询照片
 * @param text 查询文本
 * @param page
 * @param size
 * @returns
 */
export function searchByTextList(text: string) {
  return Request.axiosInstance({
    url: '/picture/search_by_text',
    method: 'get',
    params: { text }
  });
}

/**
 * 根据标签找照片
 * @param tagId
 * @param page
 * @param size
 * @returns
 */
export function searchByTagList(tagId: number, page: number, size: number) {
  return Request.axiosInstance({
    url: '/picture/search_by_tag',
    method: 'get',
    params: { tagId, page, size }
  });
}
